package com.example.basefream.controller;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basefream.entity.BizAlertUrl;
import com.example.basefream.service.BizAlertUrlService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @author L-HN
* @since 2022-04-27
*/
@Slf4j
@Api(tags = {"（勿删）实况告警列表"})
@RestController
@RequestMapping("/bizAlertUrl")
public class BizAlertUrlController {
    
    @Autowired
    public BizAlertUrlService bizAlertUrlService;

    @ApiOperation(value = "新增")
    @PostMapping("/save")
    public Object save(@RequestBody BizAlertUrl bizAlertUrl){
        boolean b = bizAlertUrlService.save(bizAlertUrl);
        return b;
    }

    @ApiOperation(value = "根据id删除")
    @PostMapping("/delete/{id}")
    public Object delete(@PathVariable("id") Long id){
        boolean b = bizAlertUrlService.removeById(id);
        return b;
    }

    @ApiOperation(value = "批量删除")
    @PostMapping("/delete/batch")
    public Object deleteBatch(@RequestBody String ids){
        List<Long> idList = (List<Long>)JSON.parse(ids);
        boolean b = bizAlertUrlService.removeByIds(idList);
        return b;
    }

    @ApiOperation(value = "列表（分页）")
    @GetMapping("/list")
    public Object list(Long pageNum, Long pageSize){
        IPage<BizAlertUrl> page = bizAlertUrlService.page(
                new Page<>(pageNum, pageSize),
                new LambdaQueryWrapper<BizAlertUrl>().eq(false, BizAlertUrl::getBizId, 0));
        return page;
    }

    @ApiOperation(value = "详情")
    @GetMapping("/get/{id}")
    public Object get(@PathVariable("id") Long id){
        BizAlertUrl bizAlertUrl = bizAlertUrlService.getById(id);
        return bizAlertUrl;
    }

    @ApiOperation(value = "根据id修改")
    @PostMapping("/update/{id}")
    public Object update(@PathVariable("id") int id, @RequestBody BizAlertUrl bizAlertUrl){
        bizAlertUrl.setBizId(id);
        boolean b = bizAlertUrlService.updateById(bizAlertUrl);
        return b;
    }

    @ApiOperation(value = "批量修改")
    @PostMapping("/update/batch")
    public Object updateBatch(@RequestBody String bizAlertUrls){
        List<BizAlertUrl> bizAlertUrlList = (List<BizAlertUrl>)JSON.parse(bizAlertUrls);
        boolean b = bizAlertUrlService.updateBatchById(bizAlertUrlList);
        return b;
    }

}